package com.yixia.pea.controller;

import com.yixia.common.core.controller.BaseController;
import com.yixia.common.core.domain.AjaxResult;
import com.yixia.common.utils.page.TableDataInfo;
import com.yixia.pea.domain.dto.PeaHzBaseDto;
import com.yixia.pea.service.PeaHzBaseService;
import com.yixia.pea.service.PeaScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 农户信息维护
 * @author: 依梦
 * @Date 2023/8/31
 */
@Slf4j
@RestController
@RequestMapping("/credit/maintain")
public class PeaMaintainController extends BaseController {


    @Autowired
    private PeaHzBaseService hzBaseService;

    @Autowired
    private PeaScoreService scoreService;
    /**
     * 农户列表查询
     */
    @GetMapping("/list")
    public TableDataInfo list(PeaHzBaseDto hzBaseDto){
        // 对数据进行查看修改
        startPageByHelper();
        List<PeaHzBaseDto> list = hzBaseService.selectListPage(hzBaseDto);
        return getDataTable(list);
    }




    /**
     * 农户列表查询
     */
    @PutMapping("/resfresh/{hzIds}")
    @Transactional
    public AjaxResult resfresh(@PathVariable Long[] hzIds){
        // hzids中的信息进行重置
        hzBaseService.resfreshRatingStatus(hzIds);
        // 根据户主ID删除创建的评分
        return toAjax(scoreService.deleteScoreByHzId(hzIds));
    }


    // 评议员评分完毕后进行定向评分
    @PostMapping("/peaCreditScoring/{hzIds}")
    public AjaxResult creditScoring(@PathVariable Long[] hzIds){
        // 对数据进行定向信用评分
        hzBaseService.creidtScoring(hzIds);

        return success();
    }



}
